//
//  UIImage+Scale.m
//  XMPP项目练习
//
//  Created by 盛 发 况 on 16/5/6.
//  Copyright © 2016年 盛 发 况. All rights reserved.
//

#import "UIImage+Scale.h"

@implementation UIImage (Scale)
- (UIImage *)scaleImageWithWidth:(CGFloat)width {

    if (self.size.width < width || width < 0) {
        return self;
    }

    CGFloat scale = self.size.width / width;
    CGFloat height = self.size.height / scale;
    
    // 生成缩小的图像 => 使用Quartz2D绘图
    CGRect rect = CGRectMake(0, 0, width, height);
    UIGraphicsBeginImageContext(rect.size);
    [self drawInRect:rect];
    
    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return result;
}

@end





